<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="文章内容">
        <!-- 以下标签用于注入富文本编辑器 -->
        <div id="editor"></div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {},
      rules: {},
      editor: {}
    };
  },
  methods: {
    initWangEditor() {
      this.editor = new this.wangEditor('#editor');
      this.editor.config.zIndex = 1;
      this.editor.create();
    },
    submitForm(formName) {
      let text = this.editor.txt.html();
      console.log(text);

      this.$alert('这是一段内容', '标题名称', {
        confirmButtonText: '确定',
        callback: action => {
          this.$message({
            type: 'info',
            message: `action: ${ action }`
          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  mounted() {
    this.initWangEditor();
  }
}
</script>